home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FGFX11.ZIP / EFFECTS.BAS next >
BASIC Source File  |  1994-04-11  |  20KB  |  596 lines

  1. '*****************************************************************************
  2. '                                                                            *
  3. '  EFFECTS.BAS                                                               *
  4. '                                                                            *
  5. '  This program demonstrates several methods of fading in an image from an   *
  6. '  off-screen video page using either Fastgraph or Fastgraph/Light.  The set *
  7. '  of routines provided herein are written for 320 x 200 graphics video      *
  8. '  modes, but they could easily be extended to work in other resolutions.    *
  9. '                                                                            *
  10. '  The examples are by no means all inclusive.  Rather, their purpose is to  *
  11. '  illustrate a few methods of creating special effects with Fastgraph or    *
  12. '  Fastgraph/Light.                                                          *
  13. '                                                                            *
  14. '  To compile this program and link it with Fastgraph:                       *
  15. '                                                                            *
  16. '     BC /O EFFECTS;               (QuickBASIC 4.x)                          *
  17. '     LINK EFFECTS,,NUL,FGQB;                                                *
  18. '                                                                            *
  19. '     BC /Fs /O EFFECTS;           (BASIC PDS 7.x)                           *
  20. '     LINK EFFECTS,,NUL,FGQBX;                                               *
  21. '                                                                            *
  22. '     BC /O EFFECTS;               (Visual Basic for DOS)                    *
  23. '     LINK EFFECTS,,NUL,FGVBDOS;                                             *
  24. '                                                                            *
  25. '  This program also can be linked with Fastgraph/Light if you replace the   *
  26. '  "FG" prefix on the above library file names with "FGL".                   *
  27. '                                                                            *
  28. '  Fastgraph (tm) and Fastgraph/Light (tm) are graphics libraries published  *
  29. '  by Ted Gruber Software.  For more info, please call, write, or FAX.       *
  30. '                                                                            *
  31. '  Ted Gruber Software                           orders/info (702) 735-1980  *
  32. '  PO Box 13408                                          FAX (702) 735-4603  *
  33. '  Las Vegas, NV  89112                                  BBS (702) 796-7134  *
  34. '                                                                            *
  35. '*****************************************************************************
  36.  
  37. REM $INCLUDE: 'fastgraf.bi'
  38.  
  39. DEFINT A-Z
  40.  
  41. REM function declarations
  42.  
  43. DECLARE SUB Announce (Message$)
  44. DECLARE FUNCTION Irandom (Min, Max)
  45.  
  46. DECLARE SUB Curtain (Delay)
  47. DECLARE SUB DiagonalFade (Delay)
  48. DECLARE SUB HorizontalRandomFade (Delay)
  49. DECLARE SUB InwardTunnelEffect (Delay)
  50. DECLARE SUB OutwardTunnelEffect (Delay)
  51. DECLARE SUB SpiralDual (Delay)
  52. DECLARE SUB SpiralLayered (Delay)
  53. DECLARE SUB SpiralNormal (Delay)
  54. DECLARE SUB SplitScreen (Delay)
  55. DECLARE SUB Unveil (Delay)
  56. DECLARE SUB VenetianBlind (Delay)
  57.  
  58. REM global variables
  59.  
  60. COMMON SHARED Delay, ScrollDelay
  61.  
  62. REM start of main program
  63.  
  64. REM make sure a 320 x 200 color graphics mode is available
  65.  
  66. NewMode = FGbestmode(320,200,2)
  67. IF (NewMode < 0) OR (NewMode = 12) THEN
  68.    PRINT "This program requires a 320 x 200 color graphics mode."
  69.    STOP
  70. END IF
  71.  
  72. REM determine the number of delay units per half clock tick
  73.  
  74. Delay = FGmeasure / 2
  75.  
  76. REM initialize Fastgraph for the selected video mode
  77.  
  78. OldMode = FGgetmode
  79. FGsetmode NewMode
  80. Status = FGallocate(1)
  81.  
  82. REM display a packed pixel run file on a hidden page
  83.  
  84. FGsethpage 1
  85. FGsetpage 1
  86. FGmove 0, 199
  87. FGdispfile "FG.PPR"+CHR$(0), 320, 1
  88. FGsetpage 0
  89.  
  90. REM compute the number of delay units needed to make the text scroll
  91. REM down at the same rate, regardless of the CPU speed or video mode
  92.  
  93. Count = 0
  94. FGwaitfor 1
  95. StartTime& = FGgetclock
  96. DO
  97.    FGscroll 0, 319, 0, 7, 4, 1
  98.    Count = Count + 1
  99. LOOP WHILE (FGgetclock = StartTime&)
  100.  
  101. ScrollDelay = (Delay / 8) - (Delay * 2) / Count
  102. IF (ScrollDelay < 0) THEN ScrollDelay = 0
  103.  
  104. REM demonstrate the inward tunnel effect
  105.  
  106. Announce "inward tunnel effect"
  107. InwardTunnelEffect 0
  108. FGwaitfor 27
  109. Announce "inward tunnel effect with delay"
  110. InwardTunnelEffect Delay
  111. FGwaitfor 27
  112.  
  113. REM demonstrate the outward tunnel effect
  114.  
  115. Announce "outward tunnel effect"
  116. OutwardTunnelEffect 0
  117. FGwaitfor 27
  118. Announce "outward tunnel effect with delay"
  119. OutwardTunnelEffect Delay
  120. FGwaitfor 27
  121.  
  122. REM demonstrate the diagonal fade
  123.  
  124. Announce "diagonal fade"
  125. DiagonalFade 0
  126. FGwaitfor 27
  127. Announce "diagonal fade with delay"
  128. DiagonalFade Delay/2
  129. FGwaitfor 27
  130.  
  131. REM demonstrate the horizontal random fade
  132.  
  133. Announce "horizontal random fade"
  134. HorizontalRandomFade Delay
  135. FGwaitfor 27
  136.  
  137. REM demonstrate the curtain effect
  138.  
  139. Announce "curtain"
  140. Curtain Delay/8
  141. FGwaitfor 27
  142.  
  143. REM demonstrate the spiral effect
  144.  
  145. Announce "spiral"
  146. SpiralNormal Delay*2
  147. FGwaitfor 27
  148.  
  149. REM demonstrate the layered spiral effect
  150.  
  151. Announce "layered spiral"
  152. SpiralLayered Delay
  153. FGwaitfor 27
  154.  
  155. REM demonstrate the dual spiral effect
  156.  
  157. Announce "dual spiral"
  158. SpiralDual Delay/2
  159. FGwaitfor 27
  160.  
  161. REM demonstrate the split screen effect
  162.  
  163. Announce "split screen"
  164. SplitScreen Delay/2
  165. FGwaitfor 27
  166.  
  167. REM demonstrate the unveil effect
  168.  
  169. Announce "unveil"
  170. Unveil Delay/4
  171. FGwaitfor 27
  172.  
  173. REM demonstrate the "venetian blind" effect
  174.  
  175. Announce "venetian blind"
  176. VenetianBlind Delay
  177. FGwaitfor 27
  178.  
  179. REM restore the original video mode and screen attributes
  180.  
  181. Status = FGfreepage(1)
  182. FGsetmode OldMode
  183. FGreset
  184.  
  185. END
  186.  
  187. '*****************************************************************************
  188. '                                                                            *
  189. '  Announce                                                                  *
  190. '                                                                            *
  191. '  Display the name of the special effect we're about to see.                *
  192. '                                                                            *
  193. '*****************************************************************************
  194.  
  195. SUB Announce (Message$)
  196.  
  197. SHARED Delay, ScrollDelay
  198.  
  199. REM clear the screen
  200.  
  201. FGerase
  202.  
  203. REM display the specified message at the top row
  204.  
  205. FGsetcolor 15
  206. Length = LEN(Message$)
  207. FGlocate 0, 20-Length/2
  208. FGtext Message$, Length
  209.  
  210. REM scroll the message to the center of the screen
  211.  
  212. FGsetcolor 0
  213.  
  214. FOR Y = 0 TO 95 STEP 4
  215.    FGscroll 0, 319, Y, Y+7, 4, 1
  216.    FGstall ScrollDelay
  217. NEXT
  218.  
  219. REM wait 1.5 seconds
  220.  
  221. FGwaitfor 27
  222.  
  223. END SUB
  224.  
  225. '*****************************************************************************
  226. '                                                                            *
  227. '  Irandom                                                                   *
  228. '                                                                            *
  229. '  Random number generator used in some of the effects.  It returns an       *
  230. '  integer between min and max inclusive.                                    *
  231. '                                                                            *
  232. '*****************************************************************************
  233.  
  234. FUNCTION Irandom (Min, Max)
  235.  
  236. Irandom = ((RND*32767) MOD (Max-Min+1)) + Min
  237.  
  238. END FUNCTION
  239.  
  240. '*****************************************************************************
  241. '                                                                            *
  242. '  Curtain                                                                   *
  243. '                                                                            *
  244. '  Reveal each row, one at a time, starting from the bottom and proceeding   *
  245. '  to the top.  This gives the effect of a curtain rising, hence the name.   *
  246. '                                                                            *
  247. '*****************************************************************************
  248.  
  249. SUB Curtain (Delay)
  250.  
  251. FOR Y = 199 TO 0 STEP -1
  252.    FGrestore 0, 319, Y, Y
  253.    FGstall Delay
  254. NEXT
  255.  
  256. END SUB
  257.  
  258. '*****************************************************************************
  259. '                                                                            *
  260. '  DiagonalFade                                                              *
  261. '                                                                            *
  262. '  This reveals the hidden page in two diagonal segments, separated by an    *
  263. '  imaginary line extending from the lower left corner to the upper right    *
  264. '  corner of the screen.  We start with the top line of the left segment and *
  265. '  the bottom line of the right segment, and continue until the entire       *
  266. '  screen is revealed.                                                       *
  267. '                                                                            *
  268. '*****************************************************************************
  269.  
  270. SUB DiagonalFade (Delay)
  271.  
  272. Xmin = 0
  273. Xmax = 319
  274. Ymin = 0
  275. Ymax = 199
  276.  
  277. WHILE (Xmax > 0)
  278.    FGrestore 0, Xmax, Ymin, Ymin+4
  279.    FGrestore Xmin, 319, Ymax-4, Ymax
  280.    FGstall Delay
  281.  
  282.    Xmin = Xmin + 8
  283.    Xmax = Xmax - 8
  284.    Ymin = Ymin + 5
  285.    Ymax = Ymax - 5
  286. WEND
  287.  
  288. END SUB
  289.  
  290. '*****************************************************************************
  291. '                                                                            *
  292. '  HorizontalRandomFade                                                      *
  293. '                                                                            *
  294. '  In this effect, the screen is divided into a series of two-pixel high     *
  295. '  rows.  Each row is revealed in random parts from left to right.  This     *
  296. '  process repeats 20 times, once for each row.  At the end, a call to the   *
  297. '  FGrestore routine guarantees that all rows are transferred.               *
  298. '                                                                            *
  299. '*****************************************************************************
  300.  
  301. SUB HorizontalRandomFade (Delay)
  302.  
  303. DIM Xpos(100)
  304.  
  305. FOR J = 0 TO 99
  306.    Xpos(J) = 0
  307. NEXT
  308.  
  309. FOR I = 1 TO 20
  310.    FOR J = 0 TO 99
  311.       Xmin = Xpos(J)
  312.       IF (Xmin < 320) THEN
  313.          Xmax = Xmin + Irandom(1,10) * 8
  314.          IF (Xmax > 320) THEN Xmax = 320
  315.          Y = J * 2
  316.          FGrestore Xmin, Xmax-1, Y, Y+1
  317.          Xpos(J) = Xmax
  318.       END IF
  319.    NEXT
  320.    FGstall Delay
  321. NEXT
  322.  
  323. REM make sure we got them all
  324.  
  325. FGrestore 0, 319, 0, 199
  326.  
  327. END SUB
  328.  
  329. '*****************************************************************************
  330. '                                                                            *
  331. '  InwardTunnelEffect                                                        *
  332. '                                                                            *
  333. '  Starting at the screen edges, reveal the screen through a series of       *
  334. '  concentric hollow rectangles.                                             *
  335. '                                                                            *
  336. '*****************************************************************************
  337.  
  338. SUB InwardTunnelEffect (Delay)
  339.  
  340. Xmin = 0
  341. Xmax = 319
  342. Ymin = 0
  343. Ymax = 199
  344.  
  345. WHILE (Xmin < Xmax)
  346.    FGrestore 0, 319, Ymin, Ymin+4
  347.    FGrestore Xmax-7, Xmax, 0, 199
  348.    FGrestore 0, 319, Ymax-4, Ymax
  349.    FGrestore Xmin, Xmin+7, 0, 199
  350.    FGstall Delay
  351.  
  352.    Xmin = Xmin + 8
  353.    Xmax = Xmax - 8
  354.    Ymin = Ymin + 5
  355.    Ymax = Ymax - 5
  356. WEND
  357.  
  358. END SUB
  359.  
  360. '*****************************************************************************
  361. '                                                                            *
  362. '  OutwardTunnelEffect                                                       *
  363. '                                                                            *
  364. '  Starting at the screen center, reveal the screen through a series of      *
  365. '  concentric hollow rectangles.                                             *
  366. '                                                                            *
  367. '*****************************************************************************
  368.  
  369. SUB OutwardTunnelEffect (Delay)
  370.  
  371. Xmin = 152
  372. Xmax = 167
  373. Ymin = 95
  374. Ymax = 104
  375.  
  376. WHILE (Xmin >= 0)
  377.    FGrestore Xmin, Xmax, Ymin, Ymin+5
  378.    FGrestore Xmax-7, Xmax, Ymin, Ymax
  379.    FGrestore Xmin, Xmax, Ymax-4, Ymax
  380.    FGrestore Xmin, Xmin+7, Ymin, Ymax
  381.    FGstall Delay
  382.  
  383.    Xmin = Xmin - 8
  384.    Xmax = Xmax + 8
  385.    Ymin = Ymin - 5
  386.    Ymax = Ymax + 5
  387. WEND
  388.  
  389. END SUB
  390.  
  391. '*****************************************************************************
  392. '                                                                            *
  393. '  SpiralDual                                                                *
  394. '                                                                            *
  395. '  In this effect, we reveal the screen through two spirals.  One spiral     *
  396. '  emanates clockwise from the screen edges to the screen center, while the  *
  397. '  other emanates counterclockwise from the center to the screen edges.      *
  398. '                                                                            *
  399. '*****************************************************************************
  400.  
  401. SUB SpiralDual (Delay)
  402.  
  403. XminOuter = 0
  404. XmaxOuter = 319
  405. YminOuter = 0
  406. YmaxOuter = 199
  407.  
  408. XminInner = 152
  409. XmaxInner = 167
  410. YminInner = 95
  411. YmaxInner = 104
  412.  
  413. WHILE (XminOuter < XminInner)
  414.    FGrestore XminOuter, XmaxOuter, YminOuter, YminOuter+4
  415.    FGstall Delay
  416.    FGrestore XminInner, XmaxInner, YmaxInner-4, YmaxInner
  417.    FGstall Delay
  418.    FGrestore XmaxOuter-7, XmaxOuter, YminOuter, YmaxOuter
  419.    FGstall Delay
  420.    FGrestore XmaxInner+1, XmaxInner+8, YminInner, YmaxInner
  421.    FGstall Delay
  422.    FGrestore XminOuter, XmaxOuter, YmaxOuter-4, YmaxOuter
  423.    FGstall Delay
  424.    FGrestore XminInner-8, XmaxInner, YminInner, YminInner+4
  425.    FGstall Delay
  426.    FGrestore XminOuter, XminOuter+7, YminOuter, YmaxOuter
  427.    FGstall Delay
  428.    FGrestore XminInner-8, XminInner-1, YminInner, YmaxInner+5
  429.    FGstall Delay
  430.  
  431.    XminOuter = XminOuter + 8
  432.    XmaxOuter = XmaxOuter - 8
  433.    YminOuter = YminOuter + 5
  434.    YmaxOuter = YmaxOuter - 5
  435.  
  436.    XminInner = XminInner - 8
  437.    XmaxInner = XmaxInner + 8
  438.    YminInner = YminInner - 5
  439.    YmaxInner = YmaxInner + 5
  440. WEND
  441.  
  442. END SUB
  443.  
  444. '*****************************************************************************
  445. '                                                                            *
  446. '  SpiralLayered                                                             *
  447. '                                                                            *
  448. '  This effect is similar to the normal spiral.  Instead of revealing the    *
  449. '  screen in one iteration, this effect does so in four iterations (layers), *
  450. '  each moving more toward the screen center.                                *
  451. '                                                                            *
  452. '*****************************************************************************
  453.  
  454. SUB SpiralLayered (Delay)
  455.  
  456. FOR I = 0 TO 3
  457.    Xmin = I * 8
  458.    Xmax = 319 - Xmin
  459.    Ymin = I * 5
  460.    Ymax = 199 - Ymin
  461.  
  462.    WHILE (Xmin < Xmax)
  463.       FGrestore Xmin, Xmax, Ymin, Ymin+4
  464.       FGstall Delay
  465.       FGrestore Xmax-7, Xmax, Ymin, Ymax
  466.       FGstall Delay
  467.       FGrestore Xmin, Xmax, Ymax-4, Ymax
  468.       FGstall Delay
  469.       FGrestore Xmin, Xmin+7, Ymin, Ymax
  470.       FGstall Delay
  471.  
  472.       Xmin = Xmin + 32
  473.       Xmax = Xmax - 32
  474.       Ymin = Ymin + 20
  475.       Ymax = Ymax - 20
  476.    WEND
  477. NEXT
  478.  
  479. END SUB
  480.  
  481. '*****************************************************************************
  482. '                                                                            *
  483. '  SpiralNormal                                                              *
  484. '                                                                            *
  485. '  This is a spiral effect in which we reveal the screen as a series of      *
  486. '  rectangles, emanating from the screen edges and proceeding clockwise to   *
  487. '  the center of the screen.                                                 *
  488. '                                                                            *
  489. '*****************************************************************************
  490.  
  491. SUB SpiralNormal (Delay)
  492.  
  493. Xmin = 0
  494. Xmax = 319
  495. Ymin = 0
  496. Ymax = 199
  497.  
  498. WHILE (Xmin < Xmax)
  499.    FGrestore Xmin, Xmax, Ymin, Ymin+19
  500.    FGstall Delay
  501.    FGrestore Xmax-31, Xmax, Ymin, Ymax
  502.    FGstall Delay
  503.    FGrestore Xmin, Xmax, Ymax-19, Ymax
  504.    FGstall Delay
  505.    FGrestore Xmin, Xmin+31, Ymin, Ymax
  506.    FGstall Delay
  507.  
  508.    Xmin = Xmin + 32
  509.    Xmax = Xmax - 32
  510.    Ymin = Ymin + 20
  511.    Ymax = Ymax - 20
  512. WEND
  513.  
  514. END SUB
  515.  
  516. '*****************************************************************************
  517. '                                                                            *
  518. '  SplitScreen                                                               *
  519. '                                                                            *
  520. '  Reveal the top half of from left to right while revealing the bottom half *
  521. '  from right to left.                                                       *
  522. '                                                                            *
  523. '*****************************************************************************
  524.  
  525. SUB SplitScreen (Delay)
  526.  
  527. Xmin = 0
  528. Xmax = 319
  529.  
  530. WHILE (Xmax > 0)
  531.    FGrestore Xmin, Xmin+7, 0, 99
  532.    FGrestore Xmax-7, Xmax, 100, 199
  533.    FGstall Delay
  534.    Xmin = Xmin + 8
  535.    Xmax = Xmax - 8
  536. WEND
  537.  
  538. END SUB
  539.  
  540. '*****************************************************************************
  541. '                                                                            *
  542. '  Unveil                                                                    *
  543. '                                                                            *
  544. '  Starting at the center, reveal the screen in small horizontal increments  *
  545. '  until we reach the left and right edges.                                  *
  546. '                                                                            *
  547. '*****************************************************************************
  548.  
  549. SUB Unveil (Delay)
  550.  
  551. Xmin = 152
  552. Xmax = 167
  553.  
  554. WHILE (Xmin >= 0)
  555.    FGrestore Xmin, Xmin+7, 0, 199
  556.    FGrestore Xmax-7, Xmax, 0, 199
  557.    FGstall Delay
  558.    Xmin = Xmin - 8
  559.    Xmax = Xmax + 8
  560. WEND
  561.  
  562. END SUB
  563.  
  564. '*****************************************************************************
  565. '                                                                            *
  566. '  VenetianBlind                                                             *
  567. '                                                                            *
  568. '  Reveal the screen in four iterations, each revealing every fourth row.    *
  569. '  The effect produced resembles opening a Venetian blind.                   *
  570. '                                                                            *
  571. '*****************************************************************************
  572.  
  573. SUB VenetianBlind (Delay)
  574.  
  575. FOR Y = 0 TO 199 STEP 4
  576.    FGrestore 0, 319, Y, Y
  577. NEXT
  578. FGstall Delay
  579.  
  580. FOR Y = 1 TO 199 STEP 4
  581.    FGrestore 0, 319, Y, Y
  582. NEXT
  583. FGstall Delay
  584.  
  585. FOR Y = 2 TO 199 STEP 4
  586.    FGrestore 0, 319, Y, Y
  587. NEXT
  588. FGstall Delay
  589.  
  590. FOR Y = 3 TO 199 STEP 4
  591.    FGrestore 0, 319, Y, Y
  592. NEXT
  593. FGstall Delay
  594.  
  595. END SUB
  596.